var vm = new Vue({
	el : '#vSign',
	data : {
		errorText : '',
		disabled : false,
		captchaSrc : 'captcha.jpg',
		formData : {
			username : '',
			password : '',
			captcha : ''
		}
	},
	methods : {
		refreshCode : function() {
			vm.captchaSrc = "captcha.jpg?t=" + $.now();
		},
		login : function(ev) {
			if (vm.formData.username === '') {
				vm.errorText = '用户名不能为空';
			} else if (vm.formData.password === '') {
				vm.errorText = '密码不能为空';
			} else if (vm.formData.captcha === '') {
				vm.errorText = '验证码不能为空'
			} else {
				$.ajax({
					type : "POST",
					url : "login",
					data : vm.formData,
					dataType : "json",
					success : function(r) {
						if (r.code == 0) {
							window.location.href = 'index.html';
						} else {
							vm.errorText = r.msg;
							for ( var key in vm.formData) {
								vm.formData[key] = ''
							}
							vm.refreshCode();
						}
					}
				})
			}
		},
		bindEvent : function(ev) {
			$(document).keyup(function(ev) {
				ev.keyCode === 13 && vm.login();
			});

		}
	},
	mounted : function() {
		this.bindEvent();
	}
})